﻿Imports Entities
Public Class CalleDAL
    Public Shared Function ListByVillaId(ByVal zId As Long) As List(Of CALLES)
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Dim query = (From rec In bd.CALLES
                        Where rec.VILLA = zId And rec.ACTIVO = True
                        Order By rec.NOMBRE Ascending
                       Select rec).ToList

                Return query
            End Using
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
    Public Shared Function List() As List(Of CALLES)
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Dim query = (From rec In bd.CALLES
                        Where rec.ACTIVO = True
                          Order By rec.NOMBRE Ascending
                       Select rec).ToList

                Return query
            End Using
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
    Public Shared Function Create(ByVal zObject As CALLES) As Boolean
        Try
            Using bd As New gas_gasdesuvecinoEntities
                bd.CALLES.Add(zObject)
                bd.SaveChanges()
                Return True
            End Using
        Catch ex As Exception
            Debug.Print("CallesDAL.Create() " + ex.Message)
            Return False
        End Try
    End Function
    Public Shared Function Update(ByVal zObject As CALLES) As CALLES
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Dim query = (From rec In bd.CALLES
                              Where rec.CALLE = zObject.CALLE
                              Select rec).Single

                query.NOMBRE = zObject.NOMBRE
                query.ACTIVO = True
                bd.SaveChanges()
                Return query
            End Using
        Catch ex As Exception
            Debug.Print("CallesDAL.Update() " + ex.Message)
            Return Nothing
        End Try
    End Function
    Public Shared Function Delete(ByVal zId As Long) As Boolean
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Dim query = (From rec In bd.CALLES
                               Where rec.CALLE = zId
                               Select rec).Single

                query.ACTIVO = False

                bd.SaveChanges()
                Return True
            End Using
        Catch ex As Exception
            Debug.Print("CallesDAL.Delete() " + ex.Message)
            Return False
        End Try
    End Function
    Public Shared Function Exist(ByVal zId As Long) As Boolean
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Dim query = (From rec In bd.CALLES
                            Where rec.CALLE = zId
                            Select rec).Count
                If query > 0 Then
                    Return True
                Else
                    Return False
                End If
            End Using
        Catch ex As Exception
            Debug.Print("CallesDAL.Exist() " + ex.Message)
            Return False
        End Try
    End Function
    Public Shared Function SearchById(ByVal zId As Long) As CALLES
        Try
            Using bd As New gas_gasdesuvecinoEntities
                Dim query = (From rec In bd.CALLES
                             Where rec.CALLE = zId And rec.ACTIVO
                             Select rec).SingleOrDefault
                Return query
            End Using
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
End Class
